package com.yuezhi.acl.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuezhi.acl.entity.SysRole;
import com.yuezhi.acl.service.SysRoleService;
import com.yuezhi.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author boys
 * @since 2020-12-16
 */
@RestController
@RequestMapping("admin/acl/role")
public class SysRoleController {

    @Autowired
    private SysRoleService roleService;

    //获取角色分页列表
    @GetMapping("{page}/{limit}")
    public R index(@PathVariable Long page, @PathVariable Long limit, SysRole role) {
        Page<SysRole> pageParam = new Page<>(page, limit);
        QueryWrapper<SysRole> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(role.getRoleName())) {
            wrapper.like("role_name", role.getRoleName());
        }
        roleService.page(pageParam, wrapper);
        return R.success().data("items", pageParam.getRecords()).data("total", pageParam.getTotal());
    }

    //新增角色
    @PostMapping("save")
    public R save(@RequestBody SysRole role) {
        roleService.save(role);
        return R.success();
    }
}

